package com.flyone.fuxiao.controller;

import com.flyone.fuxiao.common.BaseResponse;
import com.flyone.fuxiao.common.ResultUtils;
import com.flyone.fuxiao.model.vo.ChatHistoryRecordVO;
import com.flyone.fuxiao.model.vo.ChatHistoryVO;
import com.flyone.fuxiao.model.vo.DrawHistoryRecordVO;
import com.flyone.fuxiao.model.vo.PostHistoryVO;
import com.flyone.fuxiao.service.ChatHistoryService;
import com.flyone.fuxiao.service.PostHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 历史记录 控制层
 *
 * @author flyone
 * @date 2024/3/29
 */
@RestController
@RequestMapping("/history")
@Api(tags = "历史记录接口")
public class HistoryController {

    @Resource
    private PostHistoryService postHistoryService;

    @Resource
    private ChatHistoryService chatHistoryService;

    @GetMapping("/draw/all")
    @ApiOperation("获取登录用户历史记录-绘图")
    public BaseResponse<List<PostHistoryVO>> getAllDrawHistory(HttpServletRequest request) {
        List<PostHistoryVO> postHistoryVOList = postHistoryService.getAllHistory(request);
        return ResultUtils.success(postHistoryVOList);
    }

    @GetMapping("/draw/{token}")
    @ApiOperation("获取当前token聊天记录-绘图")
    public BaseResponse<List<DrawHistoryRecordVO>> getDrawHistoryRecordByToken(@PathVariable("token") String token,
                                                                 HttpServletRequest request) {
        List<DrawHistoryRecordVO> postHistoryVOList = postHistoryService.getHistoryRecordByToken(token, request);
        return ResultUtils.success(postHistoryVOList);
    }

    @DeleteMapping("/draw/{token}")
    @ApiOperation("删除当前token聊天记录-绘图")
    public BaseResponse<String> deleteDrawHistoryRecordByToken(@PathVariable("token") String token,
                                                            HttpServletRequest request) {
        String result = postHistoryService.deleteHistoryRecordByToken(token, request);
        return ResultUtils.success(result);
    }

    @GetMapping("/chat/all")
    @ApiOperation("获取登录用户历史记录-聊天")
    public BaseResponse<List<ChatHistoryVO>> getAllChatHistory(HttpServletRequest request) {
        List<ChatHistoryVO> chatHistoryVOList = chatHistoryService.getAllChatHistory(request);
        return ResultUtils.success(chatHistoryVOList);
    }

    @GetMapping("/chat/{token}")
    @ApiOperation("获取当前token聊天记录-聊天")
    public BaseResponse<List<ChatHistoryRecordVO>> getChatHistoryRecordByToken(@PathVariable("token") String token,
                                                                               HttpServletRequest request) {
        List<ChatHistoryRecordVO> postHistoryVOList = chatHistoryService.getHistoryRecordByToken(token, request);
        return ResultUtils.success(postHistoryVOList);
    }

    @DeleteMapping("/chat/{token}")
    @ApiOperation("删除当前token聊天记录-绘图")
    public BaseResponse<String> deleteChatHistoryRecordByToken(@PathVariable("token") String token,
                                                               HttpServletRequest request) {
        String result = chatHistoryService.deleteHistoryRecordByToken(token, request);
        return ResultUtils.success(result);
    }
}
